/**
 * Copyright (C), 2015-2018, 成都启迪信息技术有限公司
 * FileName: SoftfanClient
 * Author:   sjkyll
 * Date:     2018-08-02 15:15
 * Description: 测试socket
 * <author>          <time>          <version>          <desc>
 * 作者姓名         修改时间           版本号            描述
 */
package com.cdqidi.smsservice.softfanclient;

import SoftFan.EAI.runtime.message.dataBoxMessage;
import SoftFan.workflow.protocol.EAI.eaiException;
import com.cdqidi.smsservice.util.TextUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import sessionFilterClient.msg.MSG_SocketSender;
import sessionFilterClient.msg.Socket_Exception;
import sessionFilterClient.msg.sendPoolFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;

/**
 * 〈一句话功能简述〉<br>
 *
 * @author sjkyll
 * @create 2018-08-02 15:15
 * @since 1.0.0
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class SoftfanClient {

    @Value(value = "${cmpp.core_server_ip}")
    private String coreServerIp;
    @Value(value = "${cmpp.core_server_port}")
    private Integer coreServerPort;

    @Autowired
    private TextUnit textUnit;

    @Test
    public void test() throws eaiException, IOException, Socket_Exception {

        sendPoolFactory.getInstance().startup();
        MSG_SocketSender cmd = new MSG_SocketSender(coreServerIp, coreServerPort, 13001, "admin", "admin");

        String[] shortmessagesplit = textUnit.shortMessageSplit("test",null);

        dataBoxMessage sender = new dataBoxMessage();
        sender.setSendMode("SOCKET");
        sender.setProperty("Command", "SmkernelPlug");
        sender.setProperty("EXECLEVEL", "1");
        HashMap data = new HashMap();
        data.put("auto_sn","111111111111");
        data.put("msgtype","test");
        data.put("src_num","12222");
        data.put("function_id", "1");
        data.put("body", new String(shortmessagesplit[0].getBytes("UnicodeBigUnmarked"), StandardCharsets.UTF_16));
        data.put("dest_num", "212222");
        data.put("service_id", "2222");
        data.put("feetype", "222222");
        data.put("feecode","21");
        data.put("at_time", "");
        sender.setBody(data);
        cmd.send(dataBoxMessage.BINARYMSG, sender.writeByteMsg());
    }
}